package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 刘付磊
 * @date 2021/11/13 0013
 */
@RequestMapping("/users")
@RestController
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /*查询通用设置*/
    @GetMapping("/settings")
    public ResponseEntity settings(){
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }
    /*设置陌生人问题*/
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map){
        String content = (String) map.get("content");
        settingsService.saveQuestions(content);
        return ResponseEntity.ok(null);
    }
    /*通知设置*/
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map){
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
           @RequestParam(defaultValue = "1") int page,
           @RequestParam(defaultValue = "10") int size
    ){
        //1.调用service查询
        PageResult pr = settingsService.blacklist(page,size);
        //2.构造返回
        return ResponseEntity.ok(pr);
    }
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlacklist(@PathVariable("uid") Long blackUserId){
        settingsService.deleteblacklist(blackUserId);
        return ResponseEntity.ok(null);
    }
}
